package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         350,
		Discription: "两个数组的交集",
		Level:       1,
		Labels: map[string]int{
			"排序":    1,
			"双指针滑动": 1,
		},
	})
}

func Intersect(nums1 []int, nums2 []int) []int {
	m := len(nums1)
	n := len(nums2)
	//fastSort(nums1, 0, m-1)
	//fastSort(nums2, 0, n-1)

	i := 0
	j := 0
	res := make([]int, 0)
	for i < m && j < n {
		if nums1[i] == nums2[j] {
			res = append(res, nums1[i])
			i++
			j++
			continue
		}

		if nums1[i] > nums2[j] {
			j++
		} else {
			i++
		}
	}

	return res
}
